// 模拟 getScanInfo 函数
export function getScanInfo(trackingNumber) {
    return new Promise((resolve) => {
        setTimeout(() => {
            resolve({
                trackingNumber: trackingNumber,
                sender: '张三',
                recipient: '李四',
                lockerId: 'A123',
                doorId: 'D456'
            });
        }, 1000); // 模拟延迟
    });
}

// 添加状态
const state = {
    scanResult: null, // 存储快递信息
};

// 添加 mutations
const mutations = {
    SET_SCAN_RESULT(state, result) {
        state.scanResult = result;
    },
};

// 添加 actions
const actions = {
    getScanInfo({ commit }, trackingNumber) {
        getScanInfo(trackingNumber).then(result => { // 调用 API
            commit('SET_SCAN_RESULT', result); // 更新状态
        }).catch(error => {
            console.error("Error fetching scan info:", error);
        });
    },
};

// 添加 getters
const getters = {
    scanResult: (state) => state.scanResult,
};

// 导出 store
export default {
    state,
    mutations,
    actions,
    getters,
};



